﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MedReg
{
    public partial class PostGraduationEducationType : IEquatable<PostGraduationEducationType>
    {
        public void ImportList(List<Classes.PostGraduationEducationType> PGETList)
        {
            var mdb = new MedregDBDataContext();
            var ListPGET = new List<PostGraduationEducationType>();
            foreach (var pget in PGETList)
            {
                PostGraduationEducationType pget1 = new PostGraduationEducationType() { ID = pget.ID, Name = pget.Name };
                PostGraduationEducationType query;

                if (mdb.PostGraduationEducationType.LongCount() == 0)
                {
                    mdb.PostGraduationEducationType.InsertOnSubmit(pget1);
                }
                else
                {
                    try
                    {
                        query = mdb.PostGraduationEducationType.Single(l => l.ID == pget1.ID);
                        query.Name = pget1.Name;

                    }
                    catch (ArgumentNullException e)
                    {
                    }
                    catch (InvalidOperationException e)
                    {

                        if (!ListPGET.Contains(pget1))
                        {
                            mdb.PostGraduationEducationType.InsertOnSubmit(pget1);
                            ListPGET.Add(pget1);
                        }
                    }
                }
            }
            mdb.SubmitChanges();
        }
        public bool Equals(PostGraduationEducationType other)
        {
            var i = this.ID.Equals(other.ID);
            var j = this.Name.Equals(other.Name);
            if (i & j)
            {
                return true;
            }
            return false;
        }
    }
}
